
package de.hpk.jav;

import java.io.IOException;

import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;

import de.hpk.antlar.HelloLexer;
import de.hpk.antlar.HelloParser;

public class Main {
	
	public static String  expression = "12 + 2 + 6" , result = "";
	

	public static void main(String[] args) throws IOException {
		
		
		System.out.println(expression);
		result = eval(expression);
		//System.out.println(result);
	}
	
	
	public static String eval (String expression)
	{
		HelloLexer lexar = new HelloLexer(new ANTLRInputStream(expression));
		CommonTokenStream tokens = new CommonTokenStream(lexar);
		HelloParser parser = new HelloParser(tokens);
		ParseTree tree = parser.operation();
		String res = new MyVisitor().visit(tree);
		System.out.println("Aufgabe ist: " +  expression +"\n Ergebnis ist: " + res);
		return res;
	}
}

